package com.bum.api.core.bo;

import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import org.apache.commons.codec.digest.DigestUtils;

import com.bum.api.core.bo.om.App;

public class AppBO {
	static Map<String, App>	map;
	static List<App>		apps;
	static String			version	= "1";

	public App get(String code) {
		return map.get(code);
	}

	public List<App> list() {
		return apps;
	}

	public String getVersion() {
		return version;
	}

	static {
		try {
			map = DataBO.loadApps();

			StringBuilder seeds = new StringBuilder("apps ");

			apps = new LinkedList<App>();
			for (String code : map.keySet()) {
				App app = map.get(code);
				if ("1".equals(app.getShow())) {
					seeds.append(app.getCode()).append(" ");
					apps.add(app);
				}
			}

			version = DigestUtils.md5Hex(seeds.toString()).substring(28).toLowerCase();
			// Để tạm
			version = Integer.toString(apps.size());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
